import 'dart:io';

import 'package:flutter/material.dart';

import '../router/router_contract.dart';
import '../widget/pages/preview_image_page.dart';

class PreviewTool {
  static show(BuildContext context, String url) {
    return RouterContract('image',
        (BuildContext context, Map<String, dynamic> params) {
      return PreviewImagePage(imageProvider: [NetworkImage(url)]);
    }).push(context, useAndroidAnimate: true);
  }

  static showForFile(BuildContext context, File file) {
    return RouterContract('image',
        (BuildContext context, Map<String, dynamic> params) {
      return PreviewImagePage(imageProvider: [FileImage(file)]);
    }).push(context, useAndroidAnimate: true);
  }

  static showPicList(
      BuildContext context, Iterable<String> picList, int index) {
    final imageProvider = picList.map((url) => NetworkImage(url)).toList();
    return RouterContract('image',
        (BuildContext context, Map<String, dynamic> params) {
      return PreviewImagePage(index: index, imageProvider: imageProvider);
    }).push(context, useAndroidAnimate: true);
  }
}
